package com.ruoyi.web.controller.biz.hugong.openapi;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.vo.ConsumerVo;
import com.ruoyi.system.service.ICustomerService;
import com.ruoyi.system.wx.login.domain.WxLoginVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @ClassName ConsumerOpenApi
 * @Description
 * @Author sizegang
 * @Date2025/4/19 13:37
 **/
@RestController
@RequestMapping("/openapi/customer")
public class ConsumerOpenApi extends BaseController {


    @ApiOperation("用户一键登录")
    @Log(title = "【用户一键登录】", businessType = BusinessType.DELETE)
    @PostMapping("consumerLogin")
    public AjaxResult consumerLogin(@RequestBody WxLoginVo wxLoginVo) {
        return success(customerService.consumerLogin(wxLoginVo));
    }

    @Autowired
    private ICustomerService customerService;


    @ApiOperation("修改客户信息")
    @Log(title = "【客户自行注册】", businessType = BusinessType.UPDATE)
    @PostMapping("/updateConsumerInfo")
    public AjaxResult updateConsumerInfo(@RequestBody ConsumerVo consumerVo) {
        try {
            return toAjax(customerService.updateConsumerInfo(consumerVo));
        } catch (IOException e) {
            return error(e.getMessage());
        }
    }

    @ApiOperation("获取客户信息")
    @Log(title = "获取客户信息", businessType = BusinessType.UPDATE)
    @GetMapping("/getConsumerInfo")
    public AjaxResult getConsumerInfo(@RequestParam("platform") String platform, @RequestParam("phone") Long phone) {
        try {
            return success(customerService.getConsumerInfo(phone, platform));
        } catch (Exception e) {
            return error(e.getMessage());
        }
    }
}
